package com.virtualightning.mvvm.impl.adapter

import androidx.recyclerview.widget.RecyclerView
import kotlin.math.abs

/**
 *  Anchor : Create by CimZzz
 *  Time : 2021/10/20 17:21
 *  缺省的适配器滑动状态策略
 */
class DefaultAdapterScrollStrategy: IAdapterScrollStrategy {
	override fun onScrolled(dx: Int, dy: Int): Int {
		val yDistance = abs(dy)
		return when {
			yDistance >= 10 -> {
				UniverseAdapter.ScrollStateFast
			}
			yDistance > 0 -> {
				UniverseAdapter.ScrollStateSlow
			}
			else -> {
				UniverseAdapter.ScrollStateIdle
			}
		}
	}

	override fun onScrollState(newState: Int): Int? {
		return when(newState) {
			RecyclerView.SCROLL_STATE_IDLE -> {
				UniverseAdapter.ScrollStateIdle
			}
			else -> null
		}
	}
}